//
//  EmojiPictureView.swift
//  imprint
//
//  Created by 小柠檬🍋 on 2025/5/21.
//

import SwiftUI

//表情
struct EmojiView: View {
    @StateObject var viewModel = EmojiViewModel()
    
    var body: some View {
        GeometryReader { geometry in
            let spacing: CGFloat = 10 // 行间距和列间距
            let columns = Array(repeating: GridItem(.flexible(), spacing: spacing), count: 5) // 列间距
            // 计算单元格宽度（总宽度减去列间距）
            let itemWidth = (geometry.size.width - spacing * 4) / 5
            ScrollView {
                LazyVGrid(columns: columns, spacing: 10) {
                    ForEach(viewModel.tableItem, id: \.uuid) { item in
                        Rectangle()
                            .fill(Color.blue)
                            .frame(width: itemWidth, height: itemWidth) // 保证宽高相等
                            .overlay(
                                Text("测试")
                                    .foregroundColor(.white)
                                    .font(.headline)
                            )
                    }
                }
            }.onAppear{
                if !viewModel.isInit{
                    viewModel.getTab()
                    viewModel.isInit = true
                }
            }
        }
    }
}

#Preview {
    EmojiView()
}
